<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>_${customer.customerName}_重新打印发票</title>
<script type="text/javascript">
  var single_array=new Array();
  var multi_array=new Array();

  $(function() {
		$("#queryForm").validate(); 
		$("input[type='checkbox']").attr("checked",false);
		//绑定全选
		$("#alreadyMyCheckedAll").on("ifChanged", function(event){
				alreadyMyCheckedAll();
			});
		//绑定级联 
		/* $("input[name='alreadyMyChecked']").on("ifChanged", function(event){
				alreadyMyChecked($(this).val());
			}); */
  });
  
	function alreadyMyChecked(item) {
		if (!$("#check_already" + item).is(":checked")) {
			$("#alreadyMyCheckedAll").iCheck("uncheck");
		}
	}
	function alreadyMyCheckedAll() {
		//$("input[name='alreadyMyChecked']").attr("checked",$("#alreadyMyCheckedAll").is(":checked"));
		$("input[name='alreadyMyChecked']").iCheck($("#alreadyMyCheckedAll").is(":checked") ? "check" : "uncheck");
	}

	function alreadyMyCheckedAllTWS() {
		var tempChecked = [];
		$("input[type='checkbox'][name='alreadyMyChecked']:checked").each(function() {
		        tempChecked.push($(this).val());
		});
		return tempChecked ;
	}
	
	function printInvoiceNormal(){
		printInvoiceNormalFace(alreadyMyCheckedAllTWS(),"normal");
	}
	function cancelInvoice(){
		cancelInvoiceFace(alreadyMyCheckedAllTWS(),"cancel");
	}
	function cancelAndReprintInvoice(){
		cancelAndRePrintInvoiceFace(alreadyMyCheckedAllTWS(),"cancelAndRePrint");
	}
</script>
</head>

<body>
	<div id="fullbg"></div>
	<div id="dialog">
		<div>
			<img src="${ctx }/static/022.gif"></img>
		</div>
	</div>
	<section class="content">
		<div class="row">
			<div class="col-md-12">
			<div class="box-body">
			<button type="button" class="btn btn-primary" onclick="printInvoiceNormal()">打印发票</button>
			<button type="button" class="btn btn-primary" onclick="cancelInvoice()">作废发票</button>
			<button type="button" class="btn btn-primary" onclick="cancelAndReprintInvoice()">作废重打</button>
			</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">

				<!-- Primary box -->
				<div class="box box-solid box-primary">
					<div class="box-header">
						<i class="fa fa-edit"></i>
						<h3 class="box-title">订单信息</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
						<table id="contentTable"
							class="table table-striped table-bordered table-condensed">
							<thead>
								<tr>
									<th><input type="checkbox" name="alreadyMyCheckedAll"
										id="alreadyMyCheckedAll" onclick="alreadyMyCheckedAll()" />
									</th>
									<th>序号</th>
									<th>商家</th>
									<th>仓库</th>
									<th>批次编号</th>
									<th>任务编号</th>
									<th>订单号</th>
									<th>客户单号</th>
									<th>发票号</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${orderList}" var="o" step="1" varStatus="i">
									<tr>
										<td><input type="checkbox" name="alreadyMyChecked"
											id="check_already${o.order.ordeno}" value="${o.order.ordeno}"
											onclick="alreadyMyChecked(${o.id})" /></td>
										<td>${i.count}</td>
										<td><c:forEach items="${customerList}" var="customer">
												<c:if test="${o.customerCode eq customer.customerCode }">${customer.customerName}</c:if>
												</c:forEach>
										</td>
										<td><c:forEach items="${warehouseList}" var="w">
												<c:if test="${o.warehouseCode eq w.groupCode }">${w.groupName}</c:if>
											</c:forEach>
										</td>
										<td>${o.batchCode}</td>
										<td>${o.taskCode}</td>
										<td>${o.order.ordeno}</td>
										<td>${o.customerOrderno}</td>
										<td>${o.invoiceNo}</td>
										<%--<td>${fn:substring(o.createTime,0,19)}</td> --%>
										<td><c:if test="${o.invoiceNo eq null }">
												未打印发票
											</c:if> 
											<c:if test="${o.invoiceNo ne null }">
												已打印发票
											</c:if></td>
										<td>
										<c:if test="${o.cancelStatus ne 'ok' }">
										<button class="btn btn-default" id="btn_invoice_${o.id}" >已取消</button>
										</c:if>
										<c:if test="${o.cancelStatus eq 'ok' }">
											<c:if test="${o.invoiceNo eq null }">
												<button class="btn btn-primary" id="btn_invoice_${o.id}" onclick="printInvoiceNormalFace('${o.order.ordeno}',this);">打印发票</button>
											</c:if> 
											<c:if test="${o.invoiceNo ne null }">
												<button class="btn btn-primary" id="btn_cancelInvoice_${o.id}" onclick="cancelInvoiceFace('${o.order.ordeno}',this);">作废发票</button>
												<button class="btn btn-primary" id="btn_reAndCelinvoice_${o.id}" onclick="cancelAndRePrintInvoiceFace('${o.order.ordeno}',this);">作废重打</button>
											</c:if>
										
										</c:if>
											
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>

					</div>
				</div>
			</div>
		</div>
	</section>
</body>
</html>
